import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore("User", () => {
  const token = ref(uni.getStorageSync("token") || "");
  const userId = ref(uni.getStorageSync("userId") || "");

  const setToken = (newToken) => {
    token.value = newToken;
    uni.setStorageSync("token", newToken);
  };

  const setUserId = (newUserId) => {
    userId.value = newUserId;
    uni.setStorageSync("userId", newUserId);
  };

  const loginOut = () => {
    token.value = "";
    userId.value = "";
    uni.removeStorageSync("userId");
    uni.removeStorageSync("token");
  };

  return { userId, token, setToken, setUserId, loginOut };
});
